//
//  AlbumView.m
//  iOS-CtrlV
//
//  Created by 龚 杰 on 12-12-21.
//  Copyright (c) 2012年 Wang Li. All rights reserved.
//

#import "AlbumView.h"
#import "AsyncImageView.h"

@implementation AlbumView
@synthesize deleagate;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setBackgroundColor:[UIColor whiteColor]];
       

        m_ImageViews = [[NSMutableArray alloc] init];
        
        AsyncImageView* iImageView = [[AsyncImageView alloc] initWithFrame:CGRectMake(2, 2, 70, 70)];
        [iImageView setBackgroundColor:[UIColor clearColor]];
        [m_ImageViews addObject:iImageView];
        [iImageView release];
        
        AsyncImageView* iImageView1= [[AsyncImageView alloc] initWithFrame:CGRectMake(2+70, 2, 70, 70)];
        [iImageView1 setBackgroundColor:[UIColor clearColor]];
        [m_ImageViews addObject:iImageView1];
        [iImageView1 release];
        
        AsyncImageView* iImageView2= [[AsyncImageView alloc] initWithFrame:CGRectMake(2, 2+70, 70, 70)];
        [iImageView2 setBackgroundColor:[UIColor clearColor]];
        [m_ImageViews addObject:iImageView2];
        [iImageView2 release];
        
        AsyncImageView* iImageView3= [[AsyncImageView alloc] initWithFrame:CGRectMake(2+70, 2+70, 70, 70)];
        [iImageView3 setBackgroundColor:[UIColor clearColor]];
        [m_ImageViews addObject:iImageView3];
        [iImageView3 release];
        
        for (int i = 0 ; i < [m_ImageViews count]; ++i) {
            [self addSubview:(AsyncImageView*)[m_ImageViews objectAtIndex:i]];
        }
        
        UIImageView* di = [[UIImageView alloc] initWithFrame:CGRectMake(0, self.frame.size.height-8, self.frame.size.width, 8)];
        [di setImage:[UIImage imageNamed:@"collect_footer"]];
        [self addSubview:di];
        [di release];

        m_AlbumName = [[UILabel alloc] initWithFrame:CGRectMake(5, 140, 135, 33)];
        [m_AlbumName setBackgroundColor:[UIColor clearColor]];
        [m_AlbumName setFont:[UIFont systemFontOfSize:10.0f]];
        [m_AlbumName setTextColor:[UIColor colorWithRed:136.0/255.0f green:136.0/255.0f blue:136.0/255.0f alpha:1]];
        m_AlbumName.numberOfLines = 0;
        [self addSubview:m_AlbumName];
        UITapGestureRecognizer* recognizer;
        // handleSwipeFrom 是偵測到手势，所要呼叫的方法
        recognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(key)];
        // 不同的 Recognizer 有不同的实体变数
        // 例如 SwipeGesture 可以指定方向
        // 而 TapGesture 則可以指定次數
        [self addGestureRecognizer:recognizer];
        [recognizer release];
    }
    return self;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/
- (void)key
{
    if(deleagate!=nil) {
        [deleagate getAlbumViewTag:self];
    }
}
- (void)setData:(NSArray*)img name:(NSString*)_name;
{
    if ([_name length] > 0) {
        m_AlbumName.text = _name;
    }
    if ([img count]>0) {
        for (int i = 0 ; i < [img count]; ++i) {
          AsyncImageView* iImageView = (AsyncImageView*)[m_ImageViews objectAtIndex:i];
            iImageView._imageRequestURL = [img objectAtIndex:i];
            iImageView.m_BoolSetImage = YES;
            [iImageView customLoadImageFromURL];
        }
    }
    
}
- (void)dealloc
{
    [m_ImageViews removeAllObjects];
    [m_ImageViews release];
    [m_AlbumName release];
    [super dealloc];
}
@end
